#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:FileName: settings.py
:Project:
:Brand:
:Version:
:Description: 
:Author: He YinYu
:Link:
:Time: 2025/5/16 23:52
"""
from pathlib import Path
from tempfile import gettempdir

from yarl import URL

from src.utils.pydantic_settings_ex import YamlSettings
from src._version import __version__

TEMP_DIR: Path = Path(gettempdir())

APP_DIR: Path = Path(__file__).resolve().parent


class Settings(YamlSettings):

    # app settings
    app_name: str = "agent-api"
    app_version: str = __version__
    app_description: str = 'agent api serving'
    
    # unicorn settings
    host: str = '127.0.0.1'
    port: int = 3000
    workers_count: int = 1
    enable_reload: bool = False

    # log settings
    log_dir: Path = Path("logs") / app_name
    log_level: str = "DEBUG"
    log_rotation: str = "00:00"
    log_retention: str = "3 days"
    log_compression: str = "zip"

    # llm settings
    llm_model_name: str
    llm_base_url: str
    llm_api_key: str = "EMPTY"
    default_max_completion_tokens: int = 16000
    default_temperature: float = 0

    # db settings
    db_file: Path = TEMP_DIR / "db.sqlite3"

    @property
    def db_url(self) -> URL:
        return URL.build(
            scheme="sqlite",
            path=f"///{self.db_file}"
        )
    
settings = Settings()
